const wx2my = require('../../../wx2my');
const Behavior = require('../../../Behavior');
var base = require('./../../../config.js');

var app = getApp();
Page({
  data: {
    luntext: ["房型列表", "酒店详情", "酒店评价"],
    activeIndex: 0,
    imgUrls: [],
    room_id: '0',
    openTime: '',
    decorate_time: '',
    room: [],
    imgUrl: ''
  },
  onSlideChangeEnd: function(e) {
    this.setData({
      activeIndex: e.detail.current
    });
  },
  datePicker() {
    let that = this;
    my.datePicker({
      currentDate: app.util.time(),
      startDate: app.util.time(),
      endDate: app.util.addDate(app.util.time(), 28),
      success: (res) => {
        console.log(res.date);
        var a = res.date,
          o = (that.data.dateout, that.data.current_date, app.util.addDate(a, 1));
        wx2my.setStorageSync("day1", a), wx2my.setStorageSync("day2", o), wx2my.setStorageSync("day", n);
        var n = app.getTime2Time(o, a);
        that.setData({
          datein: res.date,
          dateout: o,
          time: n
        }), this.refresh();
      },
    });
  },
  datePicker2() {
    let that = this;
    my.datePicker({
      currentDate: app.util.time(),
      startDate: app.util.time(),
      endDate: app.util.addDate(app.util.time(), 28),
      success: (res) => {
        console.log(res.date);
        var e = that.data.datein,
          a = res.date;
        console.log(e + "+" + a);
        var o = app.getTime2Time(a, e);
        wx2my.setStorageSync("day1", e), wx2my.setStorageSync("day2", a), wx2my.setStorageSync("day", o),
          that.setData({
            dateout: res.date,
            time: o
          });
        // my.alert({
        //   title: 'datePicker response: ' + JSON.stringify(res)
        // });
      },
    });
  },
  onLoad: function(t) {
    console.log('hotelLoad................')
    var e = this;
    wx2my.setNavigationBarColor({
      frontColor: '#000000',
      backgroundColor: '#ffffff'
    })
    console.log(t);
    e.date();
    e.data.text;
    var a = decodeURIComponent(t.scene);
    if (null != a) var o = t.hotel_id; else o = a;
    e.setData({
      room_id: o
    });
   
    var n = wx2my.getStorageSync(["imgUrl1"]).data;
    e.setData({
      hotel_id: o,
      imgUrl: n,
      start: app.util.time(),
      end: app.util.addDate(app.util.time(), 28)
    })
    e.refresh();
  },
  commend: function() {
    wx2my.navigateTo({
      url: './comment?id=' + this.data.room_id
    });
  },
  date: function(t) {
    var e = wx2my.getStorageSync(["day1"]).data,
      a = wx2my.getStorageSync(["day2"]).data,
      o = wx2my.getStorageSync(["day"]).data,
      n = app.util.time();

    if (wx2my.setStorageSync("datein", i), "" == e) {
      var i = app.util.time();
      wx2my.setStorageSync("datein", i);
    } else if (e < n) i = n; else i = e;

    if ("" == a) var r = app.util.addDate(n, 1); else {
      var s = app.util.addDate(n, 1);
      if (a < s) r = s; else r = a;
    }
    o = app.util.day(r, i);
    wx2my.setStorageSync("day1", i), wx2my.setStorageSync("day2", r), wx2my.setStorageSync("day", o), this.setData({
      datein: i,
      dateout: r,
      time: o,
      current_date: i
    });
  },
  hotel_detail: function(t) {
    wx2my.navigateTo({
      url: "hotel_detail?hotel_id=" + t.currentTarget.dataset.id
    });
  },
  callPhone: function(e) {
    console.log(e.currentTarget.dataset.id);
    wx2my.makePhoneCall({
      phoneNumber: e.currentTarget.dataset.id
    });
  },
  refresh: function(t) {
    var n = this,
      e = n.data.hotel_id,
      i = n.data.day1;
    wx2my.newRequest({
      url: base.siteroot,
      data: {
        c: 'entry',
        a: 'wxapp',
        do: 'PjDetails',
        m: 'zh_jdgjb',
        seller_id: e
      },
      success: (t) => {
        console.log(t)
        n.setData({
          hotel: t.data,
          openTime: t.data.open_time ? t.data.open_time.slice(0, 4) : '',
          decorate_time: t.data.decorate_time ? t.data.decorate_time.slice(0, 4) : '',
          imgUrls: t.data.img.split(',')
        });
        console.log(n.data.imgUrls);
      },
      fail: (err) => { console.log(err) }
    })
    
    i = wx2my.getStorageSync(["day1"]).data;
    var r = app.util.addDate(i, 1);
    console.log(i);
    console.log(r);
    console.log('啊啊啊啊房型列表。。。。。。。。。。。。。。')
    wx2my.newRequest({
      url: base.siteroot,
      data: {
        c: 'entry',
        a: 'wxapp',
        do: 'RoomList',
        m: 'zh_jdgjb',
        seller_id: e
      },
      success: (res) => {
        console.log(res.data)
        this.setData({
          room: res.data
        })
        console.log('房型列表。。。。。。。。。。。。。。')
        var a = res.data;
        // e = function (e) {
        wx2my.newRequest({
          url: base.siteroot,
          data: {
            c: 'entry',
            a: 'wxapp',
            do: 'GetRoomCost',
            m: 'zh_jdgjb',
            room_id: 95,
            start: i,
            end: r
          },
          success: (res) => {
            console.log(res)
            console.log('啊啊啊啊...........')
          },
          fail: (err) => {
            console.log('啊啊啊啊xxxxxxxxxxxxxxxxxx...........')
          }
        })
        // }

      },
      fail: (err) => {
        console.log(err)
      }
    })

    
  },
  room_info: function(t) {
    this.data.hotel.id;
    var e = this.data.hotel;
    console.log(e);
    var a = e.tel,
      o = e.coordinates,
      n = e.address,
      i = e.name;
    wx2my.navigateTo({
      url: "room_info?coordinates=" + o + "&room_id=" + t.currentTarget.dataset.id + "&tel=" + a + "&address=" + n + "&name=" + i + "&price=" + t.currentTarget.dataset.price + "&hotel_id=" + this.data.hotel_id
    });
  },
  all_comment: function(t) {
    wx2my.navigateTo({
      url: "all_comment?seller_id=" + this.data.hotel_id
    });
  },
  sele_address: function(t) {
    var o = this.data.hotel,
      n = o.coordinates.split(",");
    wx2my.getLocation({
      type: "gcj02",
      success: function(t) {
        var e = Number(n[0]),
          a = Number(n[1]);
        wx2my.openLocation({
          latitude: e,
          longitude: a,
          name: o.name,
          address: o.address
        });
      }
    });
  },
  call_phone: function(t) {
    wx2my.makePhoneCall({
      phoneNumber: this.data.hotel.tel
    });
  },
  previewImage: function(t) {
    console.log(t);
    var e = this.data.url,
      a = [],
      o = t.currentTarget.id,
      n = t.currentTarget.dataset.index,
      i = this.data.assess_list;

    for (var r in i) if (o == i[r].id) var s = i[r].img;

    for (var l in s) a.push(e + s[l]);

    wx2my.previewImage({
      current: e + s[n],
      urls: a
    });
  },
  //预定按钮
  formSubmit: function(option) {
    // console.log(option)
    // console.log('点击了预订按钮')
    var that = this;
    var a = option.detail.formId,
      o = that.data.grade,
      n = that.data.users;
    // console.log('不缺少。。。。。')
    //2019-05-18
    var i = wx2my.getStorageSync(["day1"]).data;
    //2019-05-19
    var r = wx2my.getStorageSync(["day2"]).data;

    // wx2my.navigateTo({url:'../pay/pay'})
    //ture
    app.time_title(i, r) == 1 && (1 == option.buttonTarget.dataset.classify ? wx2my.navigateTo({
      //房间id：25                                      酒店id:115            MjA4ODAyMjg3MjU5MjU0MF8xNTU4MTQ4MTExMTA2XzUwOQ==
      url: "../place_order/place_order?room_id=" + option.buttonTarget.dataset.id + "&hotel_id=" + that.data.hotel_id + "&form_d=" + a
    }) : wx2my.navigateTo({
      url: "hour_room?room_id=" + option.detail.target.dataset.id + "&hotel_id=" + that.data.hotel_id + "&form_d=" + a + "&cost=" + option.detail.target.dataset.cost + "&rz_time=" + option.detail.target.dataset.rz_time
    }));
  },

  hotel_in: function(t) {
    wx2my.navigateTo({
      url: "hotel_in?seller_id=" + t.currentTarget.dataset.id
    });
  },
  bindgetuserinfo: function(t) {
    console.log(t), "getUserInfo:fail auth deny" == t.detail.errMsg && wx2my.showModal({
      title: "",
      content: "您拒绝了个人信息授权，无法正常使用小程序"
    });
  },
  onReady: function() { },
  onShow: function() {
    var e = this;
    app.getUserInfo(function(t) {
      console.log(t),
        e.setData({
          users: t
        });
    });
  },
  onHide: function() { },
  onUnload: function() { },
  onPullDownRefresh: function() { },
  onReachBottom: function() { },
  onShareAppMessage: function() { }
});